package com.wangshuqi;

import com.wangshuqi.app.dao.OrderMapper;
import com.wangshuqi.app.dao.UserMapper;
import com.wangshuqi.config.SpringConfig;
import com.wangshuqi.app.service.UserService;
import com.wangshuqi.mybatis.spring.MyFactoryBean;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class SpringMain {

    public static void main(String[] args) {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
        /*context.register(SpringConfig.class);

        AbstractBeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition().getBeanDefinition();
        beanDefinition.setBeanClass(MyFactoryBean.class);
        beanDefinition.getConstructorArgumentValues().addGenericArgumentValue(UserMapper.class);
        context.registerBeanDefinition("userMapper", beanDefinition);

        AbstractBeanDefinition beanDefinition1 = BeanDefinitionBuilder.genericBeanDefinition().getBeanDefinition();
        beanDefinition1.setBeanClass(MyFactoryBean.class);
        beanDefinition1.getConstructorArgumentValues().addGenericArgumentValue(OrderMapper.class);
        context.registerBeanDefinition("orderMapper", beanDefinition1);

        context.refresh();*/

        UserService userService = context.getBean(UserService.class);
        userService.test();

        OrderMapper orderMapper = context.getBean(OrderMapper.class);
        System.out.println(orderMapper.getOrderName());
    }
}
